
const mongoUtil = require("./mongo_util")
const collectionName = "cart"

function createCart(cart, callback) {
    mongoUtil.getCollection(collectionName).then(collection => {
        collection.insertOne(cart, function (err, res) {
            callback(err, res)
        });
    })
}
function getCart(cart, callback) {
    const mmp = mongoUtil.getCollection(collectionName)
    console.log("mmp=", mmp);
    console.log("cart",cart);
    mmp.then(collection => {
        
        collection.find({
            ...cart
        }).toArray(function (err, result) {
            // console.log("resultjjjj",result);
            // console.log("...cart",{...cart});
            if (result.length) {
                callback(null, result)
                new Error()
            }else{
                callback(err ? err : {
                    reason: "该用户购物车没有数据"
                }, result)
            }
        })
    })
}
module.exports = {
    createCart,
    getCart,
    
}